;; lib.inc

DispAL:
	push ecx
	push edx
	push edi
	
	mov edi, [dwDispPos]
	mov ah, 0Fh
	mov dl, al
	shr al, 4
	mov ecx, 2
.loop:
	and al, 01111b
	cmp al, 9
	ja .1
	add al, '0'
	jmp .2
.1:
	sub al, 10
	add al, 'A'
.2:
	mov [gs:edi], ax
	mov al, dl
	add edi, 2
	loop .loop
	
	
	mov [dwDispPos], edi
	
	pop edi
	pop edx
	pop ecx
	ret
	
DispInt:
	mov eax, [esp + 4]
	shr eax, 24
	call DispAL
	
	mov eax, [esp + 4]
	shr eax, 16
	call DispAL
	
	mov eax, [esp + 4]
	shr eax, 8
	call DispAL
	
	mov eax, [esp + 4]
	call DispAL
	
	push edi
	mov edi, [dwDispPos]
	mov ah, 07H
	mov al, 'h'
	mov [gs:edi], ax
	add edi, 4
	mov [dwDispPos], edi
	
	pop edi
	ret
	
DispStr:
	push ebp
	mov ebp, esp
	
	push ebx
	push esi
	push edi
	
	mov esi, [ebp + 8]
	mov edi, [dwDispPos]
	mov ah, 0Fh
	
.1:
	; 相当于mov al, [ds:esi], inc esi
	lodsb
	test al, al
	jz .2
	cmp al, 0Ah
	jnz .3
	push eax
	call DispReturn
	pop eax
	mov edi, [dwDispPos]
	jmp .1
.3:
	mov [gs:edi], ax
	add edi, 2
	jmp .1

.2:
	mov dword [dwDispPos], edi
	pop edi
	pop esi
	pop ebx
	
	pop ebp
	ret
	
; 此处跟于渊老师的稍微不一样，显示回车我没有调用DispStr，而是反过来
DispReturn:
	push ebx
	mov eax, [dwDispPos]
	mov bl, 160
	div bl
	and eax, 0FFh
	inc eax
	mov bl, 160
	mul bl
	mov [dwDispPos], eax
	pop ebx
	ret